﻿package mortal.game.view.palyer.renderer
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import flash.text.*;
    import mortal.common.global.*;
    import mortal.game.cache.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.mount.newMountModuel.*;
    import mortal.game.view.palyer.data.*;
    import mortal.mvc.core.*;

    public class SkillListCellRenderer extends GCellRenderer
    {
        private var _skillItem:OtherSkillItem;
        private var _otherInfo:GTextFiled;
        private var _skillData:FashionSkillData;

        public function SkillListCellRenderer()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._skillItem = UICompomentPool.getUICompoment(OtherSkillItem);
            this._skillItem.setBg(ImagesConst.EquipItemBg, 7, 7);
            this._skillItem.setSize(48, 48);
            this._skillItem.isDragAble = false;
            this._skillItem.x = 2;
            this._skillItem.y = 2;
            this.addChild(this._skillItem);
            this._otherInfo = UIFactory.gTextField("", 8 - 2, 8 - 6, 28 + 5, 34 + 5, this, GlobalStyle.textFormatHui);
            this._otherInfo.multiline = true;
            this._otherInfo.wordWrap = true;
            this._otherInfo.autoSize = TextFieldAutoSize.LEFT;
            this.addListeners();
            return;
        }// end function

        private function addListeners() : void
        {
            NetDispatcher.addCmdListener(ServerCommand.BackPackItemsChange, this.onSkillBookUpdateHandler);
            return;
        }// end function

        private function removeListeners() : void
        {
            NetDispatcher.removeCmdListener(ServerCommand.BackPackItemsChange, this.onSkillBookUpdateHandler);
            return;
        }// end function

        override public function set data(param1:Object) : void
        {
            super.data = param1;
            this._skillData = param1 as FashionSkillData;
            if (this._skillData)
            {
                if (this._skillData.isOpen)
                {
                    this._skillItem.isShowLock = false;
                    this._otherInfo.visible = false;
                    if (this._skillData.learnedSkill == null)
                    {
                        this._skillItem.skillInfo = this._skillData.defaultSkill;
                        this._skillItem.hasLearnSkill = false;
                    }
                    else
                    {
                        this._skillItem.skillInfo = this._skillData.learnedSkill;
                        this._skillItem.hasLearnSkill = true;
                    }
                    this.onSkillBookUpdateHandler();
                }
                else
                {
                    this._skillItem.skillInfo = this._skillData.defaultSkill;
                    this._skillItem.isShowLock = true;
                    this._skillItem.hasLearnSkill = false;
                }
            }
            return;
        }// end function

        private function onSkillBookUpdateHandler(param1:Object = null) : void
        {
            var _loc_3:ItemData = null;
            var _loc_4:int = 0;
            var _loc_5:TSkill = null;
            var _loc_6:int = 0;
            var _loc_7:Object = null;
            var _loc_8:Object = null;
            if (!this._skillData.isOpen)
            {
                return;
            }
            this._skillItem.isShowUpgradeBtn = false;
            this._skillItem.setState(OtherSkillItem.stateType_no);
            var _loc_2:* = Cache.instance.pack.backPackCache.getItemsByGroupCategoryAndType(EGroup._EGroupStuff, EStuff._EStuffAdvance, EAdvanceType._EAdvanceTypePlayer);
            if (_loc_2)
            {
                for each (_loc_3 in _loc_2)
                {
                    
                    _loc_4 = _loc_3.itemInfo.effect;
                    _loc_5 = SkillConfig.instance.getInfoById(_loc_4);
                    _loc_6 = ItemsUtil.getSkillTypeByItemData(_loc_3);
                    if (_loc_5 && this._skillItem.skillInfo.tSkill.posType == _loc_5.posType)
                    {
                        if (this._skillData.isActive)
                        {
                            if (_loc_3.itemInfo.itemLevel == (this._skillItem.skillInfo.tSkill.skillLevel + 1))
                            {
                                this._skillItem.isShowUpgradeBtn = true;
                                this._skillItem.setState(OtherSkillItem.stateType_canAdvance);
                                this._skillItem.setBtnPosition(27, 1);
                                _loc_7 = {};
                                _loc_7.skillType = _loc_6;
                                _loc_7.itemData = _loc_3;
                                this._skillItem.upgradeParam = _loc_7;
                                this._skillItem.callBack = this.upgradeSkill;
                                return;
                            }
                            continue;
                        }
                        if (this._skillItem.skillInfo.tSkill.skillLevel == _loc_3.itemInfo.itemLevel)
                        {
                            this._skillItem.isShowUpgradeBtn = true;
                            this._skillItem.setState(OtherSkillItem.stateType_canLearn);
                            this._skillItem.setBtnPosition(27, 1);
                            _loc_8 = {};
                            _loc_8.skillType = _loc_6;
                            _loc_8.itemData = _loc_3;
                            this._skillItem.upgradeParam = _loc_8;
                            this._skillItem.callBack = this.upgradeSkill;
                            return;
                        }
                    }
                }
            }
            return;
        }// end function

        private function upgradeSkill(param1:Object) : void
        {
            GameProxy.packProxy.useItem(param1.itemData.uid, param1.itemData.itemCode);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._skillItem.dispose(param1);
            this._otherInfo.dispose(param1);
            this._skillItem = null;
            this._otherInfo = null;
            this._skillData = null;
            this.removeListeners();
            return;
        }// end function

    }
}
